<template>
	<el-dialog :close-on-click-modal="false" :title="parameter.eaddrs+titlesp" :visible.sync="show" v-if="show" width="40%"
	 v-loading="loading" append-to-body>

		<div>
			<br>

			<el-card class="box-card" height="100%">
				<div slot="header" class="clearfix">
					<span>套餐列表</span>
				</div>


				<div v-if="isMore==true">
					<div v-for="item,index in fnames" class="text item" style="padding: 7px 0;">
						{{index+1}}.{{item.fnames}}
					</div>
				</div>

				<div v-else>
					<div class="text item" style="padding: 7px 0;">
						{{fnameslist}}
					</div>
				</div>


			</el-card>

			<br>
			<el-row>
				<el-tag>配送费：{{peisong}}元</el-tag>
			</el-row>
		</div>
		<div slot="footer" class="dialog-footer">
			<center>
				<el-button @click="show = false">关 闭</el-button>
			</center>
		</div>
	</el-dialog>
</template>

<script>
	import utils from 'util/utils.js';

	import constant from 'util/constant.js';
	import validate from 'util/validate.js';
	import api from 'api/order/currentorder/currentorder.js';
	export default {
		name: 'foodsfl',
		data() {
			return {
				constant: constant,
				titlesp: ' - 订单的菜品',
				type: '',
				fnameOne: '',
				isMore: false,
				loading: false,
				show: this.isDisplay,
				fnames: [],
				fnameslist: '',
				peisong: this.parameter.sendact,
				request: utils.newRequest(),
				rules: {
					mid: [{
						validator: validate.required,
						trigger: 'blur'
					}]
				}
			};
		},
		methods: {
			//改变选择项
			selectionChange(val) {
				//清空
				this.request.param.ids = [];
				for (let item of val) {
					this.request.param.ids.push(item.id);
				}
			},

			//获取数据
			list() {
				if (this.parameter.isMore == true) {
					this.fnames = this.parameter.selectTc;
					this.isMore = true;
				} else {
					this.fnameslist = this.parameter.fnameslist;
					this.isMore = false;
				}

				// if (this.parameter.isMore == true) {
				// 	console.log("true---------------")
				// 	this.thisMore = true;
				// }
				// this.fnames = []
				// if (this.parameter.fnames && this.parameter.isMore) {

				// 	// this.fnames = this.parameter.selectTc
				// 	console.log(this.fnames)
				// } else {
				// 	this.fnameOne = this.parameter.fnames;
				// }

			},
			//提交表单
			submitForm(formName) {
				utils.checkForm(this.$refs[formName], () => {
					this.loading = true;
					if (this.parameter.id) {
						//编辑
						api.update(
							this.request,
							response => {
								utils.msg.success(response.msg);
								this.loading = false;
								this.show = false;
								this.$parent.list(this.$parent.request);
							},
							response => {
								utils.msg.warning(response.msg);
								this.loading = false;
							}
						);
					} else {
						//添加
						api.save(
							this.request,
							response => {
								utils.msg.success(response.msg);
								this.loading = false;
								this.show = false;
								this.$parent.list(this.$parent.request);
							},
							response => {
								utils.msg.warning(response.msg);
								this.loading = false;
							}
						);
					}
				});
			},
			init() {
				this.isDisplay = true;
				this.list();
			}
		},
		props: {
			isDisplay: {
				type: Boolean,
				default () {
					return false;
				}
			},
			parameter: {
				type: Array | Object,
				default () {
					return {};
				}
			}
		},
		watch: {
			isDisplay(val) {
				this.show = val;
				if (val) {
					this.init();
				}
			},
			show(val) {
				this.$emit('update:isDisplay', val);
			},
			parameter(val) {
				this.parameter = val;
			}
		}
	};
</script>

<style lang="scss">
	@import '~common/custom/css/common.scss';

	.text {
		font-size: 16px;
	}



	.clearfix:before,
	.clearfix:after {
		display: table;
		content: "";
	}

	.clearfix:after {
		clear: both
	}
</style>
